﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace LookUpLater
{

    /// <summary>
    /// Item
    /// </summary>
    public class ItemType
    {
        public List<Lookup> Lookups { get; set; }
        public Type LookupType { get; set; }
        public SubCategory SubCategory { get; set; }
        public Group Group { get; set; }
        public ItemType(Type lookuptype, SubCategory subcategory, Group group, List<Lookup> lookups)
        {
            this.Lookups = lookups;
            this.LookupType = lookuptype;
            this.SubCategory = subcategory;
            this.Group = group;
        }
        public ItemType(XElement element)
        {
            this.LookupType = new Type(element.Attribute("type").Value);
            this.SubCategory = new SubCategory(element.Attribute("subcategory").Value);
            this.Group = new Group(element.Attribute("group").Value);
            this.Lookups = element.Elements("Lookup").Select(l => new Lookup(l)).ToList();
        }
        public XElement ToXml()
        {
            return new XElement("Item", new XAttribute("type", this.LookupType.Name),
                new XAttribute("subcategory", this.SubCategory.Name),
                new XAttribute("group", this.Group.Name), this.Lookups.Select(l => l.ToXml()));
        }
        public override bool Equals(object obj)
        {
            ItemType abc = obj as ItemType;
            return this.LookupType.Name.Equals(abc.LookupType.Name) && this.Group.Name.Equals(abc.Group.Name)
                && this.SubCategory.Name.Equals(abc.SubCategory.Name);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
